<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021-01-04
  Time: 15:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="<%=request.getContextPath()%>/"/>
    <link rel="stylesheet" href="webjars/layui/2.5.5/css/layui.css">
</head>
<body>


<div class="layui-main">
    <script type="text/html" id="toolbar">
        <div class="layui-form-item">
            <form class="layui-form" id="tou">
                <label class="layui-form-label">订单号:</label>
                <input type="text" name="cgName" id="cgName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left">
                <button type="button" class="layui-btn" onclick="search()" style="float: left;margin-left: 20px">查询</button>
            </form>
            <button class="layui-btn" lay-event="add" onclick="add()" style="margin-left: 20px">添加</button>
        </div>
    </script>
    <table id="roleTb" lay-filter="roleTb"></table>
    <script type="text/html" id="action">
        <a class="layui-btn layui-btn-xs" lay-event="update">修改</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
</div>


<div style="display: none" id="update">
    <form class="layui-form"  action="" lay-filter="update">
        <input type="hidden" name="id"/>
        <div class="layui-form-item" style="margin-top: 30px">
            <%--<label class="layui-form-label" style="margin-bottom: 20px">物资名称:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">物资编码:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">助记码:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">最小规格:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">最小单位:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">包装单位:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">包装规格:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">生产厂家:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
            <input type="text" name="" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">--%>
            <label class="layui-form-label" style="margin-bottom: 20px">是否禁用:</label>
            <input type="text" name="deleteFlag" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <%--<label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
            <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                <select name="city" lay-verify="required">
                    <option value=""></option>
                    <option value="0">北京</option>
                    <option value="1">上海</option>
                    <option value="2">广州</option>
                    <option value="3">深圳</option>
                    <option value="4">杭州</option>
                </select>
            </div>--%>
        </div>
    </form>
</div>



<div style="display: none" id="add">
    <form class="layui-form"  action="" lay-filter="add">
        <div class="layui-form-item" style="margin-top: 30px">
            <input name="dictionaryId" type="hidden"/>
            <label class="layui-form-label" style="margin-bottom: 20px">物资名称:</label>
            <input type="text" name="cgName" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">物资编码:</label>
            <input type="text" name="cgCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">助记码:</label>
            <input type="text" name="inputCode" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">最小规格:</label>
            <input type="text" name="spec" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">最小单位:</label>
            <input type="text" name="unit" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">包装单位:</label>
            <input type="text" name="packUnit" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">包装规格:</label>
            <input type="text" name="packSpec" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">生产厂家:</label>
            <input type="text" name="factory" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
            <input type="text" name="type" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">是否禁用:</label>
            <input type="text" name="deleteFlag" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <label class="layui-form-label" style="margin-bottom: 20px">创建者:</label>
            <input type="text" name="createBy" autocomplete="off" class="layui-input"style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
            <%--<label class="layui-form-label" style="margin-bottom: 20px">物资类别:</label>
            <div class="layui-input-inline" style="width: 200px; margin-right: 1px;float: left;margin-bottom: 20px">
                <select name="city" lay-verify="required">
                    <option value=""></option>
                    <option value="0">北京</option>
                    <option value="1">上海</option>
                    <option value="2">广州</option>
                    <option value="3">深圳</option>
                    <option value="4">杭州</option>
                </select>
            </div>--%>
        </div>

    </form>
</div>




<div id="tree"></div>

<script src="webjars/layui/2.5.5/layui.js"></script>
<script>
    //表格初始化
    layui.use(["table"],function () {
        let table=layui.table;
        table.render({
            id:"roleTb",
            elem:"#roleTb",
            url:"/chao/lingyong/search",
            toolbar: "#toolbar",
            page: true,
            cols:[[
                {title:"申领单号",field:"applyMasterNo"},
                {title:"病人名字",field:"name"},
                {title:"科室名字",field:"departmentName"},
                {title:"领用日期",field:"consumingDate"},
                {title: "操作",toolbar:"#action"}
            ]]
        })
        table.on("tool(roleTb)",function ({data,event}){
            switch (event) {
                case "update":
                    update(data);
                    break;
                case "del":
                    del(data.consumMasterId);
                    break;
            }
        });



    })



    function add(){
        layui.use(["layer","jquery","form","table"],function(){
            let $ = layui.$;
            let form = layui.form;
            let layer = layui.layer;
            let table = layui.table;
            $("#add>form")[0].reset();
            layer.open({
                type:1,
                offset:'50px',
                skin:'layui-layer-molv',
                area:["700px","450px"],
                content:$("#add"),
                btn:["确定","取消"],
                yes(){
                    let params=form.val("add");
                    console.log(params);
                    $.post("wz/add",params)
                        .done(({msg})=>{
                            table.reload("roleTb");
                            layer.close(layer.index);
                            layer.msg(msg);
                        });
                }
            });
        });
    }





    //修改
    function update(data) {
        //console.log(data);
        layui.use(["layer","jquery","form"],function () {
            let layer=layui.layer;
            let $=layui.$;
            layui.form.val("update",data);
            layer.open({
                type:1,
                offset:'50px',
                skin:'layui-layer-molv',
                area:["700px","450px"],
                content:$("#update"),
                btn:["确定","取消"],
                yes(){
                    let params=layui.form.val("update");
                    $.post("wz/update",params)
                        .done(({msg})=>{
                            layer.close(layer.index);
                            layer.msg(msg);
                            layui.table.reload("roleTb");
                        });
                }
            })
        })
    }








    function del(consumMasterId){
        layui.use("jquery",function(){
            alert(consumMasterId);
            let layer=layui.layer;
            layui.$.post('/wz/del/',{dictionaryId:consumMasterId})
                .done(({msg})=>{
                    layui.table.reload("roleTb");
                    layer.msg(msg);
                });
        });
    }



    function search() {
        layui.use('table', function() {
            let table = layui.table;
            table.reload('roleTb', {where: {cgName: document.getElementById('cgName').value}});
        })
    }



</script>

</body>
</html>
